﻿using System;
using System.Collections.Generic;

using Gonte;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MyUtilitiesTest
{
    /// <summary>
    ///This is a test class for ObjectComparerTest and is intended
    ///to contain all ObjectComparerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ObjectComparerTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void ObjectComparerAreEqualAndTheyAreEqualTest()
        {
            ObjectToTestPropertyAccessors obj1 = new ObjectToTestPropertyAccessors();
            obj1.Id = Guid.NewGuid();
            obj1.Age = 7;
            obj1.Date = new DateTime(2002, 5, 25);
            obj1.Name = "Sarah";
            obj1.Status = ObjectToTestPropertyAccessors.EnumStatus.NotTested;

            ObjectToTestPropertyAccessors obj2 = new ObjectToTestPropertyAccessors();
            obj2.Id = obj1.Id;
            obj2.Age = 7;
            obj2.Date = new DateTime(2002, 5, 25);
            obj2.Name = "Sarah";
            obj2.Status = ObjectToTestPropertyAccessors.EnumStatus.NotTested;

            List<String> modifiedPropertyNames;
            Assert.IsTrue(ObjectComparer.AreEqual(obj1, obj2, out modifiedPropertyNames));
            Assert.AreEqual(0, modifiedPropertyNames.Count);
        }

        [TestMethod()]
        public void ObjectComparerAreEqualAndTheyAreNotEqualTest()
        {
            ObjectToTestPropertyAccessors obj1 = new ObjectToTestPropertyAccessors();
            obj1.Id = Guid.NewGuid();
            obj1.Age = 6;
            obj1.Date = new DateTime(2002, 5, 25);
            obj1.Name = "Sarah";
            obj1.Status = ObjectToTestPropertyAccessors.EnumStatus.NotTested;

            ObjectToTestPropertyAccessors obj2 = new ObjectToTestPropertyAccessors();
            obj2.Id = obj1.Id;
            obj2.Age = 7;
            obj2.Date = new DateTime(2002, 5, 25);
            obj2.Name = "Shushu";
            obj2.Status = ObjectToTestPropertyAccessors.EnumStatus.NotTested;

            List<String> modifiedPropertyNames;
            Assert.IsFalse(ObjectComparer.AreEqual(obj1, obj2, out modifiedPropertyNames));
            Assert.AreEqual(2, modifiedPropertyNames.Count);
            Assert.AreEqual("Name", modifiedPropertyNames[0]);
            Assert.AreEqual("Age", modifiedPropertyNames[1]);
        }

        [TestMethod()]
        public void ObjectComparerDifferentTypesTest()
        {
            ObjectToTestPropertyAccessors obj1 = new ObjectToTestPropertyAccessors();
            Object obj2 = new Object();

            List<String> modifiedPropertyNames;
            Assert.IsFalse(ObjectComparer.AreEqual(obj1, obj2, out modifiedPropertyNames));
        }
    }
}
